package com.mycompany.myapp.service.impl;

import com.mycompany.myapp.service.RecordService;
import com.mycompany.myapp.domain.Record;
import com.mycompany.myapp.repository.RecordRepository;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.text.SimpleDateFormat;
import java.time.ZonedDateTime;
import java.util.Date;


/**
 * Service Implementation for managing Record.
 */
@Service
@Transactional
public class RecordServiceImpl implements RecordService {

    private final Logger log = LoggerFactory.getLogger(RecordServiceImpl.class);

    private final RecordRepository recordRepository;

    public RecordServiceImpl(RecordRepository recordRepository) {
        this.recordRepository = recordRepository;
    }

    /**
     * Save a record.
     *
     * @param record the entity to save
     * @return the persisted entity
     */
    @Override
    public Record save(Record record) {
        log.debug("Request to save Record : {}", record);
        ZonedDateTime date = ZonedDateTime.now();
        record.setDataTime(date);
        return recordRepository.save(record);
    }

    /**
     * Get all the records.
     *
     * @param pageable the pagination information
     * @return the list of entities
     */
    @Override
    @Transactional(readOnly = true)
    public Page<Record> findAll(Pageable pageable) {
        log.debug("Request to get all Records");
        return recordRepository.findAll(pageable);
    }

    /**
     * Get one record by id.
     *
     * @param id the id of the entity
     * @return the entity
     */
    @Override
    @Transactional(readOnly = true)
    public Record findOne(Long id) {
        log.debug("Request to get Record : {}", id);
        return recordRepository.findOne(id);
    }

    /**
     * Delete the record by id.
     *
     * @param id the id of the entity
     */
    @Override
    public void delete(Long id) {
        log.debug("Request to delete Record : {}", id);
        recordRepository.delete(id);
    }
}
